<?php
namespace app\pay\controller;
use think\Input;
class Check extends Common{
    public function initialize(){
        parent::initialize();  
    }  


    public function index()
    {
        if(request()->isPost()){
            $orderid = file_get_contents('php://input');
            $orderinfo = db('channel_order')->where('orderid_out',$orderid)->find();

            if($orderinfo['state'] === 2){
                $requestarray = array(
                    "code"   => 1,
                    "status" => 'SUCCESS',
                    'msg'    =>  array( 
                                    "orderid" =>$orderinfo['orderid'],
                                    "orderid_out" =>$orderinfo['orderid_out'],
                                    "money" => $orderinfo['money'], 
                                    "number" => $orderinfo['number'],  
                                    "version" => $orderinfo['version'],
                                    "addtime" =>date('Y-m-d H:i:s',$orderinfo['addtime']),
                                    "paytime" =>date('Y-m-d H:i:s',$orderinfo['paytime']) 
                                )                 
                );
                return json($requestarray); 
            }elseif ($orderinfo['state'] === 0) {
                $requestarray = array(
                    "code"   => 0,
                    "status" => 'FAIL',
                    'msg'    =>  array( 
                                    "orderid" =>$orderinfo['orderid'],
                                    "orderid_out" =>$orderinfo['orderid_out'],
                                    "money" => $orderinfo['money'], 
                                    "number" => $orderinfo['number'],  
                                    "version" => $orderinfo['version'],
                                    "addtime" =>date('Y-m-d H:i:s',$orderinfo['addtime'])
                                    // "paytime" =>$orderinfo['paytime']  
                                )                 
                );
                return json($requestarray);
            }else{
                $requestarray = array(
                    "code" => -1,
                    "status" => 'FAIL',
                    "msg" => '查无此订单',
                );
                 return json($requestarray); 
            }
        }else{
            $requestarray = array(
                    "code" => -2,
                    "msg" => '请按正确的方式查询',                 
            );
            return json($requestarray); 
        }

    }
  
}  